<?php
function lilina_userapi_update_garbage($args)
{
    // Get arguments from argument array
    extract($args);

    $invalid = array();
    if (!isset($unique) || !is_string($unique)) {
        $invalid[] = 'unique';
    }
    if (!isset($id) || !is_integer($id)) {
        $invalid[] = 'id';
    }
    if (count($invalid) > 0) {
        $msg = xarML('Invalid #(1) for #(2) function #(3)() in module #(4)', join(', ', $invalid), 'user', 'update_garbage', 'lilina');
        xarErrorSet(XAR_SYSTEM_EXCEPTION, 'BAD_PARAM', new SystemException($msg));
        return;
    } 
    // Security Check
    if(!xarSecurityCheck('AdminLilina')) return;

    // Get datbase setup
    $dbconn =& xarDBGetConn();
    $xartable =& xarDBGetTables();
    $gtable = $xartable['garbage'];
    $stable = $xartable['story'];
    // First we need to delete from the story page
    // Delete the item
    // Since we have hooks, we need the id.
    $query = "DELETE FROM $stable
            WHERE xar_id = ?";
    $bindvars = array($id);
    $result =& $dbconn->Execute($query,$bindvars);
    if (!$result) return;
    // Let any hooks know that we have deleted a link
    xarModCallHooks('item', 'delete', $id, '');

    // Then add it to the garbage table
    // Get next ID in table
    $nextId = $dbconn->GenId($gtable);
    // Add item
    $query = "INSERT INTO $gtable (
              xar_id,
              xar_unique)
            VALUES (
              ?, 
              ?)";
    $result =& $dbconn->Execute($query, array($nextId, $unique));
    if (!$result) return;
    // Get the ID of the item that we inserted
    $id = $dbconn->PO_Insert_ID($stable, 'xar_id');
    return $id;
} 
?>